﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows;
using System.Windows.Input;

using ASApplication;



namespace ASPresentation
{
    public class GisCommandBinder
    {

        static RoutedCommand select = new RoutedCommand();

        public static RoutedCommand Select
        {
            get { return GisCommandBinder.select; }
          
        }


        static RoutedCommand pan = new RoutedCommand();

        public static RoutedCommand Pan
        {
            get { return GisCommandBinder.pan; }
            
        }


        static RoutedCommand zoomExtent = new RoutedCommand();

        public static RoutedCommand ZoomExtent
        {
            get { return GisCommandBinder.zoomExtent; }
           
        }


        static RoutedCommand move = new RoutedCommand();

        public static RoutedCommand Move
        {
            get { return GisCommandBinder.move; }
           
        }




        static RoutedCommand addPoint = new RoutedCommand();

        public static RoutedCommand AddPoint
        {
            get { return GisCommandBinder.addPoint; }
            
        }

        static RoutedCommand addLine = new RoutedCommand();

        public static RoutedCommand AddLine
        {
            get { return GisCommandBinder.addLine; }
            
        }

        static RoutedCommand addRect = new RoutedCommand();

        public static RoutedCommand AddRect
        {
            get { return GisCommandBinder.addRect; }
           
        }

        static RoutedCommand addPoly = new RoutedCommand();

        public static RoutedCommand AddPoly
        {
            get { return GisCommandBinder.addPoly; }
          

        }



        static RoutedCommand addCircle = new RoutedCommand();

        public static RoutedCommand AddCircle
        {
            get { return GisCommandBinder.addCircle; }
           
        }


        static RoutedCommand addExp = new RoutedCommand();

        public static RoutedCommand AddExp
        {
            get { return GisCommandBinder.addExp; }
           
        }

        static RoutedCommand addCube = new RoutedCommand();

        public static RoutedCommand AddCube
        {
            get { return GisCommandBinder.addCube; }
          
        }












           /// <summary>
        /// 将命令绑定到窗体
        /// </summary>
        /// <param name="window"></param>
        public static void BindCommandsToWindow(Window window)
        {

            CommandBinding cbSelect = new CommandBinding();
            cbSelect.Command = Select;
            cbSelect.CanExecute += new CanExecuteRoutedEventHandler(cbSelect_CanExecute);
            cbSelect.Executed += new ExecutedRoutedEventHandler(cbSelect_Executed);
            window.CommandBindings.Add(cbSelect);



            CommandBinding cbMove = new CommandBinding();

            cbMove.Command = move;
            cbMove.CanExecute += new CanExecuteRoutedEventHandler(cbMove_CanExecute);
            cbMove.Executed += new ExecutedRoutedEventHandler(cbMove_Executed);
            window.CommandBindings.Add(cbMove);


            CommandBinding cbZoomExtent = new CommandBinding();
            cbZoomExtent.Command = zoomExtent;
            cbZoomExtent.Executed += new ExecutedRoutedEventHandler(cbZoomExtent_Executed);

            cbZoomExtent.CanExecute += new CanExecuteRoutedEventHandler(cbZoomExtent_CanExecute);

            window.CommandBindings.Add(cbZoomExtent);



            CommandBinding cbPan = new CommandBinding();

            cbPan.Command = Pan;
            cbPan.Executed += new ExecutedRoutedEventHandler(cbPan_Executed);

            cbPan.CanExecute += new CanExecuteRoutedEventHandler(cbPan_CanExecute);

            window.CommandBindings.Add(cbPan);




            CommandBinding cbAddPoint = new CommandBinding();
            cbAddPoint.Command = addPoint;
            cbAddPoint.CanExecute += new CanExecuteRoutedEventHandler(cbAddPoint_CanExecute);
            cbAddPoint.Executed += new ExecutedRoutedEventHandler(cbAddPoint_Executed);

            window.CommandBindings.Add(cbAddPoint);


            CommandBinding cbAddLine = new CommandBinding();

            cbAddLine.Command = addLine;
            cbAddLine.CanExecute += new CanExecuteRoutedEventHandler(cbAddLine_CanExecute);
            cbAddLine.Executed += new ExecutedRoutedEventHandler(cbAddLine_Executed);

            window.CommandBindings.Add(cbAddLine);


            CommandBinding cbAddPoly = new CommandBinding();
            cbAddPoly.Command = addPoly;
            cbAddPoly.CanExecute += new CanExecuteRoutedEventHandler(cbAddPoly_CanExecute);
            cbAddPoly.Executed += new ExecutedRoutedEventHandler(cbAddPoly_Executed);

            window.CommandBindings.Add(cbAddPoly);


            CommandBinding cbAddRect = new CommandBinding();
            cbAddRect.Command = addRect;
            cbAddRect.CanExecute += new CanExecuteRoutedEventHandler(cbAddRect_CanExecute);
            cbAddRect.Executed += new ExecutedRoutedEventHandler(cbAddRect_Executed);

            window.CommandBindings.Add(cbAddRect);



            CommandBinding cbAddCircle = new CommandBinding();

            cbAddCircle.Command = addCircle;

            cbAddCircle.CanExecute += new CanExecuteRoutedEventHandler(cbAddCircle_CanExecute);
            cbAddCircle.Executed += new ExecutedRoutedEventHandler(cbAddCircle_Executed);

            window.CommandBindings.Add(cbAddCircle);



            CommandBinding cbAddCube = new CommandBinding();
            cbAddCube.Command = addCube;
            cbAddCube.CanExecute += new CanExecuteRoutedEventHandler(cbAddCube_CanExecute);
            cbAddCube.Executed += new ExecutedRoutedEventHandler(cbAddCube_Executed);

            window.CommandBindings.Add(cbAddCube);



            CommandBinding cbAddExp = new CommandBinding();
            cbAddExp.Command = addExp;
            cbAddExp.CanExecute += new CanExecuteRoutedEventHandler(cbAddExp_CanExecute);
            cbAddExp.Executed += new ExecutedRoutedEventHandler(cbAddExp_Executed);
            window.CommandBindings.Add(cbAddExp);





        }

        static void cbZoomExtent_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;

            }
        }

        static void cbZoomExtent_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            GisService.CurrentService.CurrentMap.ZoomToMaxExtent();

        }

        static void cbMove_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            GisService.CurrentService.MapMode=(MapMode.Move);
        }

        static void cbMove_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;

            }
        }

        static void cbAddExp_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            GisService.CurrentService.MapMode=(MapMode.AddExp);
        }

        static void cbAddExp_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;

            }
        }

        static void cbAddCube_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            GisService.CurrentService.MapMode = (MapMode.AddCube);
        }

        static void cbAddCube_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;

            }
        }





        static void cbAddCircle_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            GisService.CurrentService.MapMode = (MapMode.AddCircle);
        }

        static void cbAddCircle_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;

            }
        }

        static void cbAddRect_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            GisService.CurrentService.MapMode = (MapMode.AddRect);
        }

        static void cbAddRect_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;

            }
        }

        static void cbPan_Executed(object sender, ExecutedRoutedEventArgs e)
        {

            GisService.CurrentService.MapMode = (MapMode.Pan);

        }

        static void cbPan_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;

            }
        }

        static void cbAddPoly_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            GisService.CurrentService.MapMode = (MapMode.AddPoly);
        }

        static void cbAddPoly_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;

            }

        }

        static void cbAddLine_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            GisService.CurrentService.MapMode = (MapMode.AddLine);
        }

        static void cbAddLine_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;

            }
        }


        static void cbAddPoint_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            GisService.CurrentService.MapMode = (MapMode.AddPoint);
        }

        static void cbAddPoint_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;
                
            }
        }

        static void cbSelect_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            GisService.CurrentService.MapMode = (MapMode.Select);

        }

        static void cbSelect_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;

            }
            
        }

    }
}
